<?php
class SP_Common_Global
{
	protected static $global_vars=array();
	protected static $not_overwrite=array();
	
	public static function set($name, $value, $not_overwrite=false)
	{
		if( isset(self::$not_overwrite[$name]) )
		{
			if( self::has($name) ) return false;
		}
		
		self::$global_vars[$name]=$value;
		
		if( $not_overwrite )
		{
			self::$not_overwrite[$name]=true;
		}
		return true;
	}
	
	public static function has($name)
	{
		return array_key_exists($name, self::$global_vars);
	}
	
	public static function get($name,$value=null)
	{
		return self::has($name) ? self::$global_vars[$name] : $value;
	}
	
	public static function remove($name)
	{
		unset(self::$global_vars[$name]);
		unset(self::$not_overwrite[$name]);
	}
	
	public static function getOnce($name,$value=null)
	{
		$temp=self::get($name,$value);
		self::remove($name);
		return $temp;
	}
	
	public function getAll()
	{
		return self::$global_vars;
	}
	
	public function clear()
	{
		self::$global_vars=array();
	}
}
